package com.lagou.edu.configuration;

import com.lagou.edu.annotations.MyService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.filter.AnnotationTypeFilter;

@Configuration
@ComponentScan(value = {
		"com.lagou.edu"
})
public class BeanConfiguration implements BeanDefinitionRegistryPostProcessor {
	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		ClassPathBeanDefinitionScanner scanner = new
				ClassPathBeanDefinitionScanner(registry);
		// bean 的名字生成规则在AnnotationBeanNameGenerator
		scanner.setBeanNameGenerator(new AnnotationBeanNameGenerator());
		// 设置哪些注解的扫描
		scanner.addIncludeFilter(new AnnotationTypeFilter(MyService.class));
		scanner.scan("com.lagou.edu");
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

	}
}
